package com.mrjy.aiui.bo;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mrjy.aiui.dao.IAiuiRecordInfoDao;
import com.mrjy.aiui.dao.IAiuiUserSessionInfoDao;
import com.mrjy.aiui.dto.AiuiRecordInfoExportDTO;
import com.mrjy.aiui.dto.AiuiUserSessionInfoDTO;
import com.mrjy.common.util.DateUtil;
import com.mrjy.common.util.ExcelUtil;

@Service("aiuiUserSessionInfoBo")
public class AiuiUserSessionInfoBo implements IAiuiUserSessionInfoBo {
	@Autowired
	private IAiuiUserSessionInfoDao aiuiUserSessionInfoDao ;
	@Autowired
	private IAiuiRecordInfoDao aiuiRecordInfoDao ;
	
	@Override
	public Object selectListForBack(AiuiUserSessionInfoDTO dto) {
		Map<String , Object> map = new HashMap<String , Object>() ;
		int count = aiuiUserSessionInfoDao.selectCountFoBack(dto);
		List<AiuiUserSessionInfoDTO> list  = null ;
		if(count > 0){
			list = aiuiUserSessionInfoDao.selectListForBack(dto);
		}
		map.put("err_code", 200);
		map.put("err_msg", "查询成功");
		map.put("rows", list);
		map.put("total", count) ;
		return map ;
	}

	@Override
	public Object exportExl(AiuiRecordInfoExportDTO dto,HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>() ;
		//String[] sessoionID = dto.getSessionId().split(",");
		List<AiuiRecordInfoExportDTO> list = aiuiRecordInfoDao.exportExl(dto);
		try {
			ExcelUtil.writeExcel(response, "小程序问答记录表"+DateUtil.dateToString(new Date(), DateUtil.FULL_DATE_STR)+".xls", list, AiuiRecordInfoExportDTO.class);
		} catch (IllegalArgumentException | IllegalAccessException | IOException e) {
			e.printStackTrace();
		}
		return map;
	}



}
